"""
    with 关键字的使用
"""

# 常规方法关闭流

try:
    file  = open("text.txt","w")
    file.write("a")
    # file.close()
finally:
    # 需要自己手动关闭
    print("文件是否关闭",file.closed)
    if not file.closed:
        file.close()
    print("文件是否关闭",file.closed)

try:
    # with 语句会自动关闭流
    with open("text.txt","w") as file:
        file.write("bbb")
finally:
    print(f"file status is : {file.closed}")